import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:zootix/models/zt_user_info.model.dart';
import 'package:zootix/store/zt_im_chat.store.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';
import 'package:zootix/util/zt_snack_bar.util.dart';
import 'package:zootix/constants/zt_router.dart';
import 'package:zootix/apis/zt-api.dart' as Api;
import '../util/zt_util.dart';

class ZtCustomerServicerWdiget extends StatelessWidget {
  const ZtCustomerServicerWdiget({super.key});

  @override
  Widget build(BuildContext context) {
    return InkWell(
        onTap: () async {
          ZtLogManger().putLog(
            ZtLogType.clickEvent,
            ZtLogManger.buildEvent(
                logType: ZtLogType.clickEvent, page: ZtLogPages.customer),
          );
          if (ZtImChartStore.to.imStrategy?.userServiceAccountId != null) {
            final response = await Api.getUserInfo(
                ZtImChartStore.to.imStrategy!.userServiceAccountId!);
            if (response.data != null) {
              ZtUserInfoModel userInfo =
                  ZtUserInfoModel.fromJson(response.data['data']);
              await ZtImChartStore.to.init().then((value) {
                Get.toNamed(ZtRouteConfig.privateChat, arguments: {
                  'nickname': userInfo.nickname,
                  'userId': ZtImChartStore.to.imStrategy!.userServiceAccountId,
                  'avatar': userInfo.avatar
                });
              });
            }
          }
        },
        child: Image(
            height: ZtScreenAdaper.height(40),
            width: ZtScreenAdaper.width(40),
            image: const AssetImage('assets/images/customer_servicer.png')));
  }
}
